package com.erikpasternak.vader;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

public class SharedPrefsHelper {
    public static final int MAX_INGREDIENTS = 8;

    private static final String KEY_INGREDIENTS = "ingredients";
    private static final String KEY_MAX_UNITS = "max_per_drink";
    private static final String KEY_REQUIRE_VIDEO = "use_video";
    SharedPreferences mPrefs;

    public SharedPrefsHelper(Context context) {
        mPrefs = context.getSharedPreferences("drink_prefs", 0);
    }

    public void setIngredients(String[] drinks, float[] costs) {
        StringBuilder bob = new StringBuilder();
        for (int i = 0; i < drinks.length; i++) {
            if (!TextUtils.isEmpty(drinks[i])) {
                bob.append(drinks[i]).append(";").append(costs[i]).append(";");
            }
        }
        mPrefs.edit().putString(KEY_INGREDIENTS, bob.toString()).apply();
    }

    public String[] getIngredients() {
        String[] ingredients = mPrefs.getString(KEY_INGREDIENTS,
                "vodka;0;rum;0;whiskey;0;kahlua;0;").split(
                ";");
        return ingredients;
    }

    public void setMaxUnits(int max) {
        mPrefs.edit().putInt(KEY_MAX_UNITS, max).apply();
    }

    public int getMaxUnits() {
        return mPrefs.getInt(KEY_MAX_UNITS, 24);
    }

    public void setRequireVideo(boolean useVideo) {
        mPrefs.edit().putBoolean(KEY_REQUIRE_VIDEO, useVideo).apply();
    }

    public boolean getRequireVideo() {
        return mPrefs.getBoolean(KEY_REQUIRE_VIDEO, true);
    }
}
